package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.enums.SysEngageType;

/**
 * 代理商信息
 * @author Moyq5
 * @date 2018年4月12日
 */
@Entity
@Table(name = "uc_agent")
@DynamicUpdate
public class Agent implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5300881522537175437L;
	/**
	 * 代理商ID
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "agent_id")
	private Long agentId;
	/**
	 * 上级代理
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id")
	private Agent parent;
	/**
	 * 银行账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "bank_account_id", nullable = false)
	private BankAccount bankAccount;
	/**
	 * 虚拟账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "virtual_account_id", nullable = false)
	private VirtualAccount virtualAccount;
	/**
	 * 代理商名称
	 */
    @Column(name = "name", length = 100, nullable = false)
	private String name;
	/**
	 * 级别
	 */
    @Column(name = "level", precision = 2)
	private Integer level;
    /**
     * 经营模式
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "engage_type", precision = 2, nullable = false)
	private SysEngageType engageType;
    /**
	 * 联系人
	 */
    @Column(name = "contacts", length = 60)
	private String contacts;
    /**
	 * 手机号
	 */
    @Column(name = "mobile", length = 20)
	private String mobile;
	/**
	 * 联系邮箱
	 */
    @Column(name = "email", length = 60)
	private String email;
	/**
	 * 联系电话
	 */
    @Column(name = "tel", length = 20)
	private String tel;
    
    /**
	 * 管理IP白名单，多个用回车换行区分
	 */
	@Column(name = "admin_ip", length = 100)
	private String adminIp;
	/**
	 * 提现交易限制
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "remit_confine_id")
	private TraConfine remitConfine;
	/**
	 * 提现单笔费率，如：0.0049
	 */
	@Column(name = "remit_rate", columnDefinition = "decimal(5,4) not null default '0.0000'")
	private BigDecimal remitRate;
	/**
	 * 提现单笔提现费（元）
	 */
	@Column(name = "remit_fee", columnDefinition = "decimal(10,2) not null default '2.00'")
	private BigDecimal remitFee;
	/**
	 * 提现自动出款时间，（24小时）多选，注意，此参数由上级代理管制
	 */
	@Column(name = "remit_hours", precision = 8, scale = 0, columnDefinition = "int(8) not null default '16777215'")
	private Integer remitHours;
	/**
	 * (子商户或者子代理)提现自动出款时间，（24小时）多选，注意，此参数由上级自营代理商管制
	 * @see {@link SysEngageType}
	 */
	@Column(name = "remit_sub_hours", precision = 8, scale = 0, columnDefinition = "int(8) not null default '16777215'")
	private Integer remitSubHours;
    /**
	 * 添加（注册）时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == remitRate) {
			remitRate = new BigDecimal("0.0000");
		}
		if (null == remitFee) {
			remitFee = new BigDecimal("2.00");
		}
		if (null == remitHours) {
			remitHours = 16777215;
		}
		if (null == remitSubHours) {
			remitSubHours = 16777215;
		}
		if (null == addTime) {
			addTime = new Date();
		}
	}
	public Long getAgentId() {
		return agentId;
	}
	public void setAgentId(Long agentId) {
		this.agentId = agentId;
	}
	public Agent getParent() {
		return parent;
	}
	public void setParent(Agent parent) {
		this.parent = parent;
	}
	public BankAccount getBankAccount() {
		return bankAccount;
	}
	public void setBankAccount(BankAccount bankAccount) {
		this.bankAccount = bankAccount;
	}
	public VirtualAccount getVirtualAccount() {
		return virtualAccount;
	}
	public void setVirtualAccount(VirtualAccount virtualAccount) {
		this.virtualAccount = virtualAccount;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getLevel() {
		return level;
	}
	public void setLevel(Integer level) {
		this.level = level;
	}
	public String getContacts() {
		return contacts;
	}
	public void setContacts(String contacts) {
		this.contacts = contacts;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	public String getAdminIp() {
		return adminIp;
	}
	public void setAdminIp(String adminIp) {
		this.adminIp = adminIp;
	}
	public SysEngageType getEngageType() {
		return engageType;
	}
	public void setEngageType(SysEngageType engageType) {
		this.engageType = engageType;
	}
	public BigDecimal getRemitRate() {
		return remitRate;
	}
	public void setRemitRate(BigDecimal remitRate) {
		this.remitRate = remitRate;
	}
	public BigDecimal getRemitFee() {
		return remitFee;
	}
	public void setRemitFee(BigDecimal remitFee) {
		this.remitFee = remitFee;
	}
	public TraConfine getRemitConfine() {
		return remitConfine;
	}
	public void setRemitConfine(TraConfine remitConfine) {
		this.remitConfine = remitConfine;
	}
	public Integer getRemitHours() {
		return remitHours;
	}
	public void setRemitHours(Integer remitHours) {
		this.remitHours = remitHours;
	}
	public Integer getRemitSubHours() {
		return remitSubHours;
	}
	public void setRemitSubHours(Integer remitSubHours) {
		this.remitSubHours = remitSubHours;
	}
	
}
